﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace TfsExtensions.Build.Activities.Entities
{
    public struct AssemblyFileVersionSettings
    {
        public bool IsFileVersionSelected { get; set; }
        public string Major { get; set; }
        public string Minor { get; set; }
        public string Build { get; set; }
        public string Revision { get; set; }

        public override string ToString()
        {
            string buildNumber = string.Empty;
            string revisionNumber = "*";
            if (string.IsNullOrEmpty(Build))
            {
                DateTime date = DateTime.Now;
                int day = date.DayOfYear;
                int year = Int32.Parse(string.Format(CultureInfo.InvariantCulture, "{0:yy}", date), CultureInfo.InvariantCulture);
                buildNumber = string.Format(CultureInfo.InvariantCulture, "{0:}{1:000}", year, day);
            }
            else
            {
                buildNumber = this.Build;
            }

            if(!String.IsNullOrEmpty(this.Revision))
            {
                revisionNumber = this.Revision;
            }

            return string.Format("{0}.{1}.{2}.{3}", this.Major, this.Minor, buildNumber, revisionNumber);
        }
    }
}
